package com.mrduan.otgfilemanager;

import android.net.Uri;
import android.os.Environment;

import com.github.mjdev.libaums.fs.UsbFile;
import com.shike.baselibrary.BaseConfig;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by snoopy on 2018/4/27.
 */

public class Config extends BaseConfig {
    public static final String sdCardPath = Environment.getExternalStorageDirectory().getAbsolutePath();

    public static String BASE_FILE_PATH = "";
    public static List<String> oneScreenFiles = new ArrayList<>();
    public static List<String> twoScreenFiles = new ArrayList<>();
    public static List<String> threeScreenFiles = new ArrayList<>();

    public static List<UsbFile> oneScreenUsbFiles = new ArrayList<>();
    public static List<UsbFile> twoScreenUsbFiles = new ArrayList<>();
    public static List<UsbFile> threeScreenUsbFiles = new ArrayList<>();

    public static File shareFile;
    public static UsbFile shareUsbFile;

    public static final String AIDEO_LOCAL = "AIDEO_LOCAL_";

    public static String Url = "http://localhost:8888/";

    public static String secondToMin(int second) {// 格式：00：00
        String time = "";

        second = second / 1000;

        int m = second / 60;
        int s = second % 60;

        if (m < 10) {
            time = "0" + m + ":";
        } else {
            time = m + ":";
        }
        if (s < 10) {
            time += "0" + s;
        } else {
            time += s;
        }

        return time;
    }



    public static boolean isVideo(File file) {
        return isVideo(file.getName());
    }

    public static boolean isVideo(String name) {
        boolean isVideo = false;

        String[] strings = name.split("\\.");
        if (strings.length > 0)
            name = strings[strings.length-1];

        if (name.equalsIgnoreCase("mp4")) {
            isVideo = true;
        }

        return isVideo;
    }


    /**
     * 获取文件Uri
     *
     * @param file
     * @return
     */
    public static String getUrl(UsbFile file) {
        return Config.Url + Uri.encode(getPath(file));
    }

    /**
     * 获取文件路径
     *
     * @param file
     * @return
     */
    public static String getPath(UsbFile file) {
        String path = "";

        while (!file.isRoot()) {
            if (file.isDirectory()) {
                path = file.getName()+ "/"+ path;
            } else {
                path = file.getName();
            }

            file = file.getParent();
//            path = "/"+file.getName()+ path;
//            getPath(file.getParent(),path);
//            return path;
        }

        return path;
    }

    /**
     * 判断字符串是不是纯数字
     *
     * @param str
     * @return
     */
    public static boolean isNumeric(String str) {
        for (int i = str.length(); --i >= 0; ) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }
}
